import request1 from '@/utils/request1'
export async function getCode(phone) {
  return await request1({
    method: 'POST',
    url: '/sms/code',
    data: {
      phone
    }
  })
}

export async function login(phone, code) {
  return await request1({
    method: 'POST',
    url: '/sms/login',
    data: {
      phone,
      code
    }
  })
}

export async function validateJWT(jwt) {
  // 确保JWT值不是undefined或null
  if (!jwt) {
    throw new Error('JWT token is missing.')
  }

  // 创建请求头
  const headers = {
    Authorization: `Bearer ${jwt}`, // 将JWT添加到Authorization头部
    'Content-Type': 'application/json' // 根据你的API需求设置Content-Type
  }

  // 发送带有JWT的请求
  return await request1({
    method: 'POST',
    url: '/sms/validateJWT',
    headers: headers // 将headers对象传递给请求配置
  })
}
